﻿using AutoMapper;
using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Write.API.Command.RoleCommand;
using MediatR;

namespace B.S.BaseData.Write.API.CommandHandler.RoleHandler
{
    public class DelRoleUserHandler : IRequestHandler<DelRoleUserCommand, APIResult<object>>
    {
        private readonly IBaseRepository<UserRole> urRep;
        private readonly IMapper mapper;

        public DelRoleUserHandler(IBaseRepository<UserRole> urRep,IMapper mapper)
        {
            this.urRep = urRep;
            this.mapper = mapper;
        }
        public async Task<APIResult<object>> Handle(DelRoleUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var entity = urRep.GetAll().Where(x=>x.URId==request.URId).FirstOrDefault();
            urRep.Del(entity);
            result.Code = APIEnum.Success;
            result.Msg = "删除成功";
            return await Task.FromResult(result);
        }
    }
}
